home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / Developer Essentials Jul 90 / Apple II / Programming & Utilities / Apple IIgs APW Intro Prog Src / HP.ASM / EVENT.ASM.txt < prev    next >
Encoding:
Text File  |  1987-08-31  |  14.4 KB  |  431 lines

  1.  
  2. ******************************************************************************
  3. *                                                                            *
  4. *         HodgePodge:  An example Apple IIGS Desktop application             *
  5. *                                                                            *
  6. *         Written in 65816 Assembler by the Apple IIGS Tools Team            *
  7. *  Modified by Ben Koning for "Programmer's Introduction to the Apple IIGS"  *
  8. *                                                                            *
  9. *             Copyright (c) 1986-87 by Apple Computer, Inc.                  *
  10. *                                                                            *
  11. *   ----------------------------------------------------------------------   *
  12. *                                                                            *
  13. *   ASM65816 Code file "EVENT.ASM" -- TaskMaster call; Dispatching to all    *
  14. *                                     other routines; Menu dimming.          *
  15. *                                                                            *
  16. ******************************************************************************
  17.  
  18.  
  19.  
  20. ****************************************************************
  21. *
  22. * Event
  23. *
  24. * This contains the main event loop.
  25. *
  26. ****************************************************************
  27.  
  28. MainEvent      START
  29.                using GlobalData
  30.  
  31. Again          anop
  32.  
  33.                lda QuitFlag             ;Has Quit been select?
  34.                bne AllDone              ;... if so, stop the loop.
  35.  
  36.                jsr CheckFrontW          ;Handle the menu dis/enable
  37.  
  38.                PushWord #0
  39.                PushWord #$FFFF
  40.                PushLong #EventRecord
  41.                _TaskMaster
  42.  
  43.                pla
  44.                beq Again                ;No event? loop.
  45.  
  46.                asl a                    ;Multiply by two...
  47.                tax                      ;use for index into...
  48.                jsr (TaskTable,x)        ;dispatch table to execute events.
  49.  
  50.                bra Again                ;Loop.
  51.  
  52. AllDone        rts
  53.  
  54. TaskTable      anop
  55. ;----------------------------------------------------
  56. ;
  57. ; Event manager events
  58. ;
  59.                dc i'ignore'             ; 0 null
  60.                dc i'ignore'             ; 1 mouse down
  61.                dc i'ignore'             ; 2 mouse up
  62.                dc i'ignore'             ; 3 key down
  63.                dc i'ignore'             ; 4 undefined
  64.                dc i'ignore'             ; 5 auto-key down
  65.                dc i'ignore'             ; 6 update event
  66.                dc i'ignore'             ; 7 undefined
  67.                dc i'DoActivate'         ; 8 activate
  68.                dc i'ignore'             ; 9 switch
  69.                dc i'ignore'             ; 10 desk acc
  70.                dc i'ignore'             ; 11 device driver
  71.                dc i'ignore'             ; 12 ap
  72.                dc i'ignore'             ; 13 ap
  73.                dc i'ignore'             ; 14 ap
  74.                dc i'ignore'             ; 15 ap
  75.  
  76. ;----------------------------------------------------
  77. ;
  78. ; Task master events
  79.  
  80.                dc i'ignore'             ; 0 in desk
  81.                dc i'DoMenu'             ; 1 in MenuBar
  82.                dc i'ignore'             ; 2 in system window
  83.                dc i'ignore'             ; 3 in content of window
  84.                dc i'ignore'             ; 4 in drag
  85.                dc i'ignore'             ; 5 in grow
  86.                dc i'DoCloseItem'        ; 6 in goaway -- same as "Close" item
  87.                dc i'ignore'             ; 7 in zoom
  88.                dc i'ignore'             ; 8 in info bar
  89.                dc i'DoMenu'             ; 9 in special menu item
  90.                dc i'ignore'             ; 10 in OpenNDA
  91.                dc i'ignore'             ; 11 in frame
  92.                dc i'ignore'             ; in drop
  93.  
  94.                END
  95.  
  96. ****************************************************************
  97. *
  98. * CheckFrontW
  99. *
  100. * Checks to see if front window has changed and if
  101. * so deals with various menu enables and disables.
  102. * called by main event loop, and activate events.
  103. *
  104. ****************************************************************
  105. CheckFrontW    Start
  106.                using MenuData
  107.                using GlobalData
  108.  
  109.                PushLong #0
  110.                _FrontWindow
  111.                PullLong ThisWindow      ;get the current front window.
  112.  
  113.                lda ThisWindow           ;Check to see if it is
  114.                cmp LastWindow           ;still the same window as
  115.                bne Changed              ;last time
  116.                lda ThisWindow+2
  117.                cmp LastWindow+2
  118.                bne Changed
  119.  
  120. Exit1          rts                      ;No Change No problem....Else.
  121.  
  122. Changed        anop
  123.                lda ThisWindow           ;LastWindow := ThisWindow
  124.                sta LastWindow
  125.                lda ThisWindow+2
  126.                sta LastWindow+2
  127.  
  128.                jsr TypeThisW            ;set ThisWType=type of the new front win
  129.  
  130.                lda ThisWType            ;arriving here, the window has changed.
  131.                cmp LastWType            ;it's type may not have changed.
  132.                beq Exit1                ;Branch taken if the latter is true.
  133.  
  134. !ok so start changing menus
  135.  
  136.                cmp #0                   ;is there a front window
  137.                bne ThereIs1             ;take this branch if there is.
  138.  
  139.                jsr SetupForNoW          ;if no front window then disable
  140.                bra FinishUp             ;various thing I care about and go
  141. !                                       ;Finish up
  142.  
  143. ThereIs1       ANOP
  144.                cmp #1                   ;is it a system (Da)
  145.                bne NotSysW              ;taken if not.
  146.  
  147.                jsr SetUpForDaW          ;else it is a da. do what's needed
  148.                bra FinishUp             ;and do the exit stuff
  149.  
  150. NotSysW        jsr SetUpForAppW         ;A-reg = Wtype. Go deal w/menu stuff
  151.  
  152. ! And drop into exit stuff
  153.  
  154. FinishUp       lda NeedToUpdate         ;has the menu bar changed
  155.                beq ReallyDone           ;taken if not. else
  156.  
  157.                _DrawMenuBar             ;we need to re-draw the menu
  158.                stz NeedToUpdate         ;and say we did it.
  159.  
  160. ReallyDone     lda ThisWType            ;LastWType := ThisWType
  161.                sta LastWType
  162.                rts
  163.  
  164. * figure out the type of the front window.
  165. * 0= there is no window. 1 = it's a da window. 2 = App Font Win. 3= App Pic Win.
  166.  
  167. TypeThisW      anop
  168.                lda ThisWindow           ;was there a window at all ?
  169.                ora ThisWindow+2
  170.                sta ThisWType            ;if no front window then ThisWtype=0
  171.                beq DoneEarly            ;taken if there really was no front win
  172.  
  173.                PushWord #0              ;get and save wuther or not
  174.                PushLong ThisWindow      ;this is a
  175.                _GetSysWFlag             ;system window or not.
  176.                pla
  177.                beq WasApp               ;0 means not a sys window
  178.  
  179.                lda #1                   ;it's a sys (da) window so
  180.                sta ThisWType            ;set lastwtype = 1
  181. DoneEarly      rts
  182.  
  183. WasApp         Anop                     ;it's an app win. find out what kind.
  184.  
  185.                PushLong #0              ;space for get ref con in a sec
  186.                PushLong ThisWindow      ;else I have the window ptr
  187.  
  188.                _GetWrefCon              ;get refcon it has handle to data
  189.  
  190.                pla                      ;recon handle to
  191.                sta Temp                 ;temp and A/X
  192.                plx
  193.                stx Temp+2
  194.  
  195.                jsr deref               ;lock it down for a sec
  196.  
  197.                sta 0
  198.                stx 2
  199.  
  200.                ldy #oFlag               ;check if picture
  201.                lda [0],y                ;get window type
  202.                beq PicW
  203.  
  204.                lda #2                   ;it's a font window so...
  205.                sta ThisWType            ;say so and
  206.                bra OuttaHere            ;split
  207.  
  208. PicW           lda #3                   ;it's a pic window. so
  209.                sta ThisWType            ;say so and split.
  210.  
  211. OuttaHere      lda Temp
  212.                ldx Temp+2
  213.                jsr Unlock               ;unlock the refcon handle.'
  214.                rts
  215.  
  216. Temp           ds 4
  217.  
  218.  
  219. ThisWindow     ds 4
  220. LastWindow     ds 4
  221.  
  222.                END
  223.  
  224. ****************************************************************
  225. *
  226. * doQuitItem
  227. *
  228. * Sets quit flag.
  229. *
  230. ****************************************************************
  231. doQuitItem     START
  232.                using GlobalDATA
  233.  
  234.                lda #True
  235.                sta QuitFlag
  236.  
  237.                rts
  238.                END
  239.  
  240. ******************************************************************
  241. *
  242. * DoActivate
  243. *
  244. * Handles activation of windows and adjusts the edit meun
  245. * based on window type.
  246. *
  247. ******************************************************************
  248. DoActivate     Start
  249.                using GlobalData
  250.  
  251.                lda EventModifiers
  252.                and #1
  253.                beq end                  ;don't care about deactivate ?
  254.  
  255.                jsr CheckFrontW
  256. end            rts
  257.                END
  258.  
  259. ******************************************************************
  260. *
  261. * SetUpForAppW
  262. *
  263. * Sets the edit menu items up for the application window:
  264. * that is disabling them. And sets the other file menu items
  265. * accordingly.
  266. *
  267. ******************************************************************
  268. SetUpForAppW   Start
  269.                Using GlobalData
  270.                Using MenuData
  271.  
  272.                PushLong #0              ;get ready to call changeMitems
  273.                PushWord #SaveID         ;We gonna do save item. but we need
  274.  
  275.                lda ThisWType            ;to figure out whether it should be
  276.                cmp #3                   ;enabled or not. is it a font window ?
  277.                bne NoSaveEnable         ;if so dont enable the save item.
  278.  
  279.                PushWord #True           ;else push true for enable
  280.                bra Cont
  281.  
  282. NoSaveEnable   PushWord #False
  283.  
  284. Cont           PushWord #CloseWID
  285.                PushWord #True
  286.  
  287.                lda PrintAvail
  288.                beq SkipPrint 
  289.  
  290.                PushWord #PrintID
  291.                PushWord #True
  292.                PushWord #SetUpID
  293.                PushWord #True
  294. SkipPrint      jsr ChangeMItems
  295.  
  296.                lda LastWType
  297.                cmp #1                   ;was it a da last ?
  298.                bne Exit                 ;if not we don't need to do whats next
  299.  
  300.                PushWord #$0080          ;disable edit menu
  301.                PushWord #EditMenuID
  302.                _SetMenuFlag
  303.                lda #True                ;set update flag so I only redraw
  304.                sta NeedToUpdate         ;the menu bar once
  305.  
  306. Exit           rts
  307.  
  308.                END
  309.  
  310. ******************************************************************
  311. *
  312. * SetUpForNoW
  313. *
  314. * Sets the edit menu items up for the desk acc window:
  315. * that is enabling edit menu, and close in file menu.
  316. * accordingly.
  317. *
  318. ******************************************************************
  319. SetUpForNoW    START
  320.                Using GlobalData
  321.                Using MenuData
  322.  
  323.                PushLong #0              ;end of list mark first...
  324.                PushWord #SaveID         ;disble save
  325.                PushWord #False          ;i desire disable.
  326.                PushWord #PrintID
  327.                PushWord #False
  328.                PushWord #SetUpID
  329.                PushWord #False
  330.                PushWord #CloseWID
  331.                PushWord #False          ;enable
  332.                jsr ChangeMItems
  333.  
  334.                lda LastWType            ;what was it last
  335.                cmp #1                   ;was it a da last ?
  336.                bne Exit                 ;if not we don't need to do whats next
  337.  
  338.                PushWord #$0080          ;disable edit menu
  339.                PushWord #EditMenuID
  340.                _SetMenuFlag
  341.                lda #True                ;set update flag so I only redraw
  342.                sta NeedToUpdate         ;the menu bar once
  343.  
  344. Exit           rts
  345.                End
  346.  
  347. ******************************************************************
  348. *
  349. * SetUpForDaW
  350. *
  351. * Sets the edit menu items up for the desk acc window:
  352. * that is enabling edit menu, and close in file menu.
  353. * accordingly.
  354. *
  355. ******************************************************************
  356. SetUpForDaW    START
  357.                Using GlobalData
  358.                Using MenuData
  359.  
  360.                PushLong #0              ;end of list mark first...
  361.                PushWord #SaveID         ;disble save
  362.                PushWord #False          ;i desire disable.
  363.                PushWord #PrintID
  364.                PushWord #False
  365.                PushWord #SetUpID
  366.                PushWord #False
  367.  
  368.                PushWord #CloseWID
  369.                PushWord #True           ;enable
  370.                jsr ChangeMItems
  371.  
  372.                lda LastWType            ;what was it last
  373.                cmp #1                   ;was it a da window last ?
  374.                beq Exit                 ;if so we don't need to do whats next
  375.  
  376.                PushWord #$ff7f          ;enable edit menu
  377.                PushWord #EditMenuID
  378.                _SetMenuFlag
  379.                lda #True                ;set update flag so I only redraw
  380.                sta NeedToUpdate         ;the menu bar once
  381.  
  382. Exit           rts
  383.  
  384.                END
  385.  
  386. ******************************************************************
  387. *
  388. * ChangeMItems
  389. *
  390. * Enables/Disables the various menu items according to the
  391. * flags pushed on stack.
  392. *
  393. * Entry Stack Looks like:
  394. *
  395. *                0                      ;long indicator of end of items
  396. *                ItemID                 ;word item id
  397. *                Enable/Disable Flag    ;(word) true = enable
  398. *                .
  399. *                ItemID                 ;word item id
  400. *                Enable/Disable Flag    ;(word) true = enable
  401. *                .
  402. *                Return                 ;word
  403. *        Sp =>
  404. *
  405. ******************************************************************
  406. ChangeMItems   Start
  407.  
  408.                PullWord RtaTemp         ;save return
  409.  
  410. Lp             lda 3,s                  ;check for end of list mark
  411.                beq Done                 ;if so split
  412.  
  413.                pla
  414.                bne DoEnable             ;taken if we should enable items
  415.  
  416.                _DisableMItem            ;else disable them
  417.                bra Lp                   ;and start over
  418.  
  419. DoEnable       _EnableMItem             ;enable item
  420.                bra Lp                   ;one more time
  421.  
  422. Done           PullLong                 ;pull end of list mark
  423.  
  424.                PushWord RtaTemp         ;push return address
  425.                rts
  426.  
  427. RtaTemp        ds 2
  428. EnableFlag     ds 2
  429.  
  430.                END
  431.